﻿namespace Smart.ERP
{
    using DevExpress.XtraEditors;
    using Smart.Data.Helper;
    using Smart.Utils.Lib;
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.IO;
    using System.Windows.Forms;

    public class PRODUCT
    {
        private bool m_Active;
        private double m_AverageCost;
        private string m_Barcode;
        private bool m_Batch;
        private string m_Color;
        private double m_Commission;
        private int m_CostMethod;
        private double m_CurrentCost;
        private string m_Customer_ID;
        private string m_Customer_Name;
        private double m_Depth;
        private string m_Description;
        private double m_Discount;
        private bool m_Expiry;
        private double m_ExpiryValue;
        private double m_ExportTax_ID;
        private double m_Height;
        private double m_ImportTax_ID;
        private double m_LimitOrders;
        private double m_LuxuryTax_ID;
        private int m_Manufacturer_ID;
        private double m_MaxStock;
        private double m_MinStock;
        private double m_Org_Price;
        private string m_Origin;
        private Image m_photo;
        private string m_Product_Group_ID;
        private string m_Product_ID;
        private string m_Product_Name;
        private int m_Product_Type_ID;
        private string m_Provider_ID;
        private double m_Quantity;
        private double m_Retail_Price;
        private double m_Sale_Price;
        private string m_Size;
        private double m_Thickness;
        private string m_Unit;
        private string m_UnitConvert;
        private double m_UnitRate;
        private string m_UserID;
        private double m_VAT_ID;
        private int m_Warranty;
        private double m_Width;

        public PRODUCT()
        {
            this.m_Product_ID = "";
            this.m_Product_Name = "";
            this.m_Product_Type_ID = 0;
            this.m_Manufacturer_ID = 0;
            this.m_Product_Group_ID = "";
            this.m_Provider_ID = "";
            this.m_Origin = "";
            this.m_Barcode = "";
            this.m_Unit = "";
            this.m_UnitConvert = "";
            this.m_UnitRate = 0.0;
            this.m_Org_Price = 0.0;
            this.m_Sale_Price = 0.0;
            this.m_Retail_Price = 0.0;
            this.m_Quantity = 0.0;
            this.m_CurrentCost = 0.0;
            this.m_AverageCost = 0.0;
            this.m_Warranty = 0;
            this.m_VAT_ID = 0.0;
            this.m_ImportTax_ID = 0.0;
            this.m_ExportTax_ID = 0.0;
            this.m_LuxuryTax_ID = 0.0;
            this.m_Customer_ID = "";
            this.m_Customer_Name = "";
            this.m_CostMethod = 0;
            this.m_MinStock = 0.0;
            this.m_MaxStock = 0.0;
            this.m_Discount = 0.0;
            this.m_Commission = 0.0;
            this.m_Description = "";
            this.m_Color = "";
            this.m_Expiry = true;
            this.m_LimitOrders = 0.0;
            this.m_ExpiryValue = 0.0;
            this.m_Batch = true;
            this.m_Depth = 0.0;
            this.m_Height = 0.0;
            this.m_Width = 0.0;
            this.m_Thickness = 0.0;
            this.m_Size = "";
            this.m_UserID = "";
            this.m_Active = true;
        }

        public PRODUCT(string Product_ID, string Product_Name, int Product_Type_ID, int Manufacturer_ID, string Product_Group_ID, string Provider_ID, string Origin, string Barcode, string Unit, string UnitConvert, double UnitRate, double Org_Price, double Sale_Price, double Retail_Price, double Quantity, double CurrentCost, double AverageCost, int Warranty, double VAT_ID, double ImportTax_ID, double ExportTax_ID, double LuxuryTax_ID, string Customer_ID, string Customer_Name, int CostMethod, double MinStock, double MaxStock, double Discount, double Commission, string Description, string Color, bool Expiry, double LimitOrders, double ExpiryValue, bool Batch, double Depth, double Height, double Width, double Thickness, string Size, string UserID, bool Active)
        {
            this.m_Product_ID = Product_ID;
            this.m_Product_Name = Product_Name;
            this.m_Product_Type_ID = Product_Type_ID;
            this.m_Manufacturer_ID = Manufacturer_ID;
            this.m_Product_Group_ID = Product_Group_ID;
            this.m_Provider_ID = Provider_ID;
            this.m_Origin = Origin;
            this.m_Barcode = Barcode;
            this.m_Unit = Unit;
            this.m_UnitConvert = UnitConvert;
            this.m_UnitRate = UnitRate;
            this.m_Org_Price = Org_Price;
            this.m_Sale_Price = Sale_Price;
            this.m_Retail_Price = Retail_Price;
            this.m_Quantity = Quantity;
            this.m_CurrentCost = CurrentCost;
            this.m_AverageCost = AverageCost;
            this.m_Warranty = Warranty;
            this.m_VAT_ID = VAT_ID;
            this.m_ImportTax_ID = ImportTax_ID;
            this.m_ExportTax_ID = ExportTax_ID;
            this.m_LuxuryTax_ID = LuxuryTax_ID;
            this.m_Customer_ID = Customer_ID;
            this.m_Customer_Name = Customer_Name;
            this.m_CostMethod = CostMethod;
            this.m_MinStock = MinStock;
            this.m_MaxStock = MaxStock;
            this.m_Discount = Discount;
            this.m_Commission = Commission;
            this.m_Description = Description;
            this.m_Color = Color;
            this.m_Expiry = Expiry;
            this.m_LimitOrders = LimitOrders;
            this.m_ExpiryValue = ExpiryValue;
            this.m_Batch = Batch;
            this.m_Depth = Depth;
            this.m_Height = Height;
            this.m_Width = Width;
            this.m_Thickness = Thickness;
            this.m_Size = Size;
            this.m_UserID = UserID;
            this.m_Active = Active;
        }

        public void AddCombo(System.Windows.Forms.ComboBox combo)
        {
            MyLib.TableToComboBox(combo, this.GetList(), "PRODUCT_Name", "PRODUCT_ID");
        }

        public void AddComboAll(System.Windows.Forms.ComboBox combo)
        {
            DataTable list = new DataTable();
            list = this.GetList();
            DataRow row = list.NewRow();
            row["PRODUCT_ID"] = "All";
            row["PRODUCT_Name"] = "Tất cả";
            list.Rows.InsertAt(row, 0);
            MyLib.TableToComboBox(combo, list, "PRODUCT_Name", "PRODUCT_ID");
        }

        public string ChangeId(SqlTransaction myTransaction, string idSrc, string idDesc)
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            string[] myParams = new string[] { "@IdSrc", "@IdDesc" };
            object[] myValues = new object[] { idSrc, idDesc };
            return helper.ExecuteNonQuery(myTransaction, "PRODUCT_ChangeProductId", myParams, myValues);
        }

        public string Delete()
        {
            string[] myParams = new string[] { "@Product_ID" };
            object[] myValues = new object[] { this.m_Product_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("PRODUCT_Delete", myParams, myValues);
        }

        public string Delete(string Product_ID)
        {
            string[] myParams = new string[] { "@Product_ID" };
            object[] myValues = new object[] { Product_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("PRODUCT_Delete", myParams, myValues);
        }

        public string Delete(SqlConnection myConnection, string Product_ID)
        {
            string[] myParams = new string[] { "@Product_ID" };
            object[] myValues = new object[] { Product_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "PRODUCT_Delete", myParams, myValues);
        }

        public string Delete(SqlTransaction myTransaction, string Product_ID)
        {
            string[] myParams = new string[] { "@Product_ID" };
            object[] myValues = new object[] { Product_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "PRODUCT_Delete", myParams, myValues);
        }

        private void DispError(object sender, SqlHelperException e)
        {
            XtraMessageBox.Show(e.Message, "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }

        public bool Exist(string Product_ID)
        {
            bool hasRows = false;
            string[] myParams = new string[] { "@Product_ID" };
            object[] myValues = new object[] { Product_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("PRODUCT_Get", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                reader = null;
            }
            helper.Close();
            return hasRows;
        }

        public bool Exist(SqlTransaction myTransaction, string Product_ID)
        {
            bool hasRows = false;
            string[] myParams = new string[] { "@Product_ID" };
            object[] myValues = new object[] { Product_ID };
            SqlDataReader reader = new SqlHelper().ExecuteReader(myTransaction, "PRODUCT_Get", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                reader.Dispose();
            }
            return hasRows;
        }

        public bool ExistByName(string Product_Name)
        {
            bool hasRows = false;
            string[] myParams = new string[] { "@Product_Name" };
            object[] myValues = new object[] { "%" + Product_Name + "%" };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("PRODUCT_GetByName", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                reader = null;
            }
            helper.Close();
            return hasRows;
        }

        public bool ExistByName(SqlTransaction myTransaction, string Product_Name)
        {
            bool hasRows = false;
            string[] strArray = new string[] { "@Product_Name" };
            object[] objArray = new object[] { Product_Name };
            SqlHelper helper = new SqlHelper();
            helper.CommandType = CommandType.Text;
            SqlDataReader reader = helper.ExecuteReader("Select * from PRODUCT WHERE Product_Name=N'" + Product_Name + "'");
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                reader = null;
            }
            helper.Close();
            return hasRows;
        }

        public string Get(string Product_ID)
        {
            string str = "";
            string[] myParams = new string[] { "@Product_ID" };
            object[] myValues = new object[] { Product_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("PRODUCT_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_Product_ID = Convert.ToString(reader["Product_ID"]);
                    this.m_Product_Name = Convert.ToString(reader["Product_Name"]);
                    this.m_Product_Type_ID = Convert.ToInt32(reader["Product_Type_ID"]);
                    this.m_Manufacturer_ID = Convert.ToInt32(reader["Manufacturer_ID"]);
                    this.m_Product_Group_ID = Convert.ToString(reader["Product_Group_ID"]);
                    this.m_Provider_ID = Convert.ToString(reader["Provider_ID"]);
                    this.m_Origin = Convert.ToString(reader["Origin"]);
                    this.m_Barcode = Convert.ToString(reader["Barcode"]);
                    this.m_Unit = Convert.ToString(reader["Unit"]);
                    this.m_UnitConvert = Convert.ToString(reader["UnitConvert"]);
                    this.m_UnitRate = Convert.ToSingle(reader["UnitRate"]);
                    this.m_Org_Price = Convert.ToSingle(reader["Org_Price"]);
                    this.m_Sale_Price = Convert.ToSingle(reader["Sale_Price"]);
                    this.m_Retail_Price = Convert.ToSingle(reader["Retail_Price"]);
                    this.m_Quantity = Convert.ToSingle(reader["Quantity"]);
                    this.m_CurrentCost = Convert.ToSingle(reader["CurrentCost"]);
                    this.m_AverageCost = Convert.ToSingle(reader["AverageCost"]);
                    this.m_Warranty = Convert.ToInt32(reader["Warranty"]);
                    this.m_VAT_ID = Convert.ToSingle(reader["VAT_ID"]);
                    this.m_ImportTax_ID = Convert.ToSingle(reader["ImportTax_ID"]);
                    this.m_ExportTax_ID = Convert.ToSingle(reader["ExportTax_ID"]);
                    this.m_LuxuryTax_ID = Convert.ToSingle(reader["LuxuryTax_ID"]);
                    this.m_Customer_ID = Convert.ToString(reader["Customer_ID"]);
                    this.m_Customer_Name = Convert.ToString(reader["Customer_Name"]);
                    this.m_CostMethod = Convert.ToInt16(reader["CostMethod"]);
                    this.m_MinStock = Convert.ToSingle(reader["MinStock"]);
                    this.m_MaxStock = Convert.ToSingle(reader["MaxStock"]);
                    this.m_Discount = Convert.ToSingle(reader["Discount"]);
                    this.m_Commission = Convert.ToSingle(reader["Commission"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    this.m_Color = Convert.ToString(reader["Color"]);
                    this.m_Expiry = Convert.ToBoolean(reader["Expiry"]);
                    this.m_LimitOrders = Convert.ToSingle(reader["LimitOrders"]);
                    this.m_ExpiryValue = Convert.ToSingle(reader["ExpiryValue"]);
                    this.m_Batch = Convert.ToBoolean(reader["Batch"]);
                    this.m_Depth = Convert.ToSingle(reader["Depth"]);
                    this.m_Height = Convert.ToSingle(reader["Height"]);
                    this.m_Width = Convert.ToSingle(reader["Width"]);
                    this.m_Thickness = Convert.ToSingle(reader["Thickness"]);
                    this.m_Size = Convert.ToString(reader["Size"]);
                    this.m_UserID = Convert.ToString(reader["UserID"]);
                    this.m_Active = Convert.ToBoolean(reader["Active"]);
                    if (!reader.IsDBNull(reader.GetOrdinal("Photo")) && (reader["Photo"] != Convert.DBNull))
                    {
                        byte[] buffer = (byte[]) reader["Photo"];
                        if (buffer.Length != 2)
                        {
                            MemoryStream stream = new MemoryStream(buffer);
                            this.m_photo = Image.FromStream(stream);
                        }
                        if (buffer.Length == 2)
                        {
                            this.m_photo = null;
                        }
                    }
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlConnection myConnection, string Product_ID)
        {
            string str = "";
            string[] myParams = new string[] { "@Product_ID" };
            object[] myValues = new object[] { Product_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myConnection, "PRODUCT_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_Product_ID = Convert.ToString(reader["Product_ID"]);
                    this.m_Product_Name = Convert.ToString(reader["Product_Name"]);
                    this.m_Product_Type_ID = Convert.ToInt32(reader["Product_Type_ID"]);
                    this.m_Manufacturer_ID = Convert.ToInt32(reader["Manufacturer_ID"]);
                    this.m_Product_Group_ID = Convert.ToString(reader["Product_Group_ID"]);
                    this.m_Provider_ID = Convert.ToString(reader["Provider_ID"]);
                    this.m_Origin = Convert.ToString(reader["Origin"]);
                    this.m_Barcode = Convert.ToString(reader["Barcode"]);
                    this.m_Unit = Convert.ToString(reader["Unit"]);
                    this.m_UnitConvert = Convert.ToString(reader["UnitConvert"]);
                    this.m_UnitRate = Convert.ToSingle(reader["UnitRate"]);
                    this.m_Org_Price = Convert.ToSingle(reader["Org_Price"]);
                    this.m_Sale_Price = Convert.ToSingle(reader["Sale_Price"]);
                    this.m_Retail_Price = Convert.ToSingle(reader["Retail_Price"]);
                    this.m_Quantity = Convert.ToSingle(reader["Quantity"]);
                    this.m_CurrentCost = Convert.ToSingle(reader["CurrentCost"]);
                    this.m_AverageCost = Convert.ToSingle(reader["AverageCost"]);
                    this.m_Warranty = Convert.ToInt32(reader["Warranty"]);
                    this.m_VAT_ID = Convert.ToSingle(reader["VAT_ID"]);
                    this.m_ImportTax_ID = Convert.ToSingle(reader["ImportTax_ID"]);
                    this.m_ExportTax_ID = Convert.ToSingle(reader["ExportTax_ID"]);
                    this.m_LuxuryTax_ID = Convert.ToSingle(reader["LuxuryTax_ID"]);
                    this.m_Customer_ID = Convert.ToString(reader["Customer_ID"]);
                    this.m_Customer_Name = Convert.ToString(reader["Customer_Name"]);
                    this.m_CostMethod = Convert.ToInt16(reader["CostMethod"]);
                    this.m_MinStock = Convert.ToSingle(reader["MinStock"]);
                    this.m_MaxStock = Convert.ToSingle(reader["MaxStock"]);
                    this.m_Discount = Convert.ToSingle(reader["Discount"]);
                    this.m_Commission = Convert.ToSingle(reader["Commission"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    this.m_Color = Convert.ToString(reader["Color"]);
                    this.m_Expiry = Convert.ToBoolean(reader["Expiry"]);
                    this.m_LimitOrders = Convert.ToSingle(reader["LimitOrders"]);
                    this.m_ExpiryValue = Convert.ToSingle(reader["ExpiryValue"]);
                    this.m_Batch = Convert.ToBoolean(reader["Batch"]);
                    this.m_Depth = Convert.ToSingle(reader["Depth"]);
                    this.m_Height = Convert.ToSingle(reader["Height"]);
                    this.m_Width = Convert.ToSingle(reader["Width"]);
                    this.m_Thickness = Convert.ToSingle(reader["Thickness"]);
                    this.m_Size = Convert.ToString(reader["Size"]);
                    this.m_UserID = Convert.ToString(reader["UserID"]);
                    this.m_Active = Convert.ToBoolean(reader["Active"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlTransaction myTransaction, string Product_ID)
        {
            string str = "";
            string[] myParams = new string[] { "@Product_ID" };
            object[] myValues = new object[] { Product_ID };
            SqlDataReader reader = new SqlHelper().ExecuteReader(myTransaction, "PRODUCT_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_Product_ID = Convert.ToString(reader["Product_ID"]);
                    this.m_Product_Name = Convert.ToString(reader["Product_Name"]);
                    this.m_Product_Type_ID = Convert.ToInt32(reader["Product_Type_ID"]);
                    this.m_Manufacturer_ID = Convert.ToInt32(reader["Manufacturer_ID"]);
                    this.m_Product_Group_ID = Convert.ToString(reader["Product_Group_ID"]);
                    this.m_Provider_ID = Convert.ToString(reader["Provider_ID"]);
                    this.m_Origin = Convert.ToString(reader["Origin"]);
                    this.m_Barcode = Convert.ToString(reader["Barcode"]);
                    this.m_Unit = Convert.ToString(reader["Unit"]);
                    this.m_UnitConvert = Convert.ToString(reader["UnitConvert"]);
                    this.m_UnitRate = Convert.ToSingle(reader["UnitRate"]);
                    this.m_Org_Price = Convert.ToSingle(reader["Org_Price"]);
                    this.m_Sale_Price = Convert.ToSingle(reader["Sale_Price"]);
                    this.m_Retail_Price = Convert.ToSingle(reader["Retail_Price"]);
                    this.m_Quantity = Convert.ToSingle(reader["Quantity"]);
                    this.m_CurrentCost = Convert.ToSingle(reader["CurrentCost"]);
                    this.m_AverageCost = Convert.ToSingle(reader["AverageCost"]);
                    this.m_Warranty = Convert.ToInt32(reader["Warranty"]);
                    this.m_VAT_ID = Convert.ToSingle(reader["VAT_ID"]);
                    this.m_ImportTax_ID = Convert.ToSingle(reader["ImportTax_ID"]);
                    this.m_ExportTax_ID = Convert.ToSingle(reader["ExportTax_ID"]);
                    this.m_LuxuryTax_ID = Convert.ToSingle(reader["LuxuryTax_ID"]);
                    this.m_Customer_ID = Convert.ToString(reader["Customer_ID"]);
                    this.m_Customer_Name = Convert.ToString(reader["Customer_Name"]);
                    this.m_CostMethod = Convert.ToInt16(reader["CostMethod"]);
                    this.m_MinStock = Convert.ToSingle(reader["MinStock"]);
                    this.m_MaxStock = Convert.ToSingle(reader["MaxStock"]);
                    this.m_Discount = Convert.ToSingle(reader["Discount"]);
                    this.m_Commission = Convert.ToSingle(reader["Commission"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    this.m_Color = Convert.ToString(reader["Color"]);
                    this.m_Expiry = Convert.ToBoolean(reader["Expiry"]);
                    this.m_LimitOrders = Convert.ToSingle(reader["LimitOrders"]);
                    this.m_ExpiryValue = Convert.ToSingle(reader["ExpiryValue"]);
                    this.m_Batch = Convert.ToBoolean(reader["Batch"]);
                    this.m_Depth = Convert.ToSingle(reader["Depth"]);
                    this.m_Height = Convert.ToSingle(reader["Height"]);
                    this.m_Width = Convert.ToSingle(reader["Width"]);
                    this.m_Thickness = Convert.ToSingle(reader["Thickness"]);
                    this.m_Size = Convert.ToString(reader["Size"]);
                    this.m_UserID = Convert.ToString(reader["UserID"]);
                    this.m_Active = Convert.ToBoolean(reader["Active"]);
                    str = "OK";
                }
                reader.Dispose();
                reader = null;
            }
            return str;
        }

        public string Get(string Product_ID, string Stock_ID)
        {
            string str = "";
            string[] myParams = new string[] { "@Product_ID", "@Stock_ID" };
            object[] myValues = new object[] { Product_ID, Stock_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("PRODUCT_GetByStock", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_Product_ID = Convert.ToString(reader["Product_ID"]);
                    this.m_Product_Name = Convert.ToString(reader["Product_Name"]);
                    this.m_Unit = Convert.ToString(reader["Unit"]);
                    this.m_UnitConvert = Convert.ToString(reader["UnitConvert"]);
                    this.m_UnitRate = Convert.ToSingle(reader["UnitRate"]);
                    this.m_Org_Price = Convert.ToSingle(reader["Org_Price"]);
                    this.m_Quantity = Convert.ToSingle(reader["Quantity"]);
                    this.m_AverageCost = Convert.ToSingle(reader["AverageCost"]);
                    this.m_Product_Type_ID = Convert.ToInt32(reader["Product_Type_ID"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string GetByStockAll(string Product_ID, string Stock_ID)
        {
            string str = "";
            string[] myParams = new string[] { "@Product_ID", "@Stock_ID" };
            object[] myValues = new object[] { Product_ID, Stock_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("PRODUCT_GetByStockAll", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_Product_ID = Convert.ToString(reader["Product_ID"]);
                    this.m_Product_Name = Convert.ToString(reader["Product_Name"]);
                    this.m_Unit = Convert.ToString(reader["Unit"]);
                    this.m_UnitConvert = Convert.ToString(reader["UnitConvert"]);
                    this.m_UnitRate = Convert.ToSingle(reader["UnitRate"]);
                    this.m_Org_Price = Convert.ToSingle(reader["Org_Price"]);
                    this.m_Quantity = Convert.ToSingle(reader["Quantity"]);
                    this.m_AverageCost = Convert.ToSingle(reader["AverageCost"]);
                    this.m_Product_Type_ID = Convert.ToInt32(reader["Product_Type_ID"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string GetByStockAll(SqlTransaction myTransaction, string Product_ID, string Stock_ID)
        {
            string str = "";
            string[] myParams = new string[] { "@Product_ID", "@Stock_ID" };
            object[] myValues = new object[] { Product_ID, Stock_ID };
            SqlDataReader reader = new SqlHelper().ExecuteReader(myTransaction, "PRODUCT_GetByStockAll", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_Product_ID = Convert.ToString(reader["Product_ID"]);
                    this.m_Product_Name = Convert.ToString(reader["Product_Name"]);
                    this.m_Unit = Convert.ToString(reader["Unit"]);
                    this.m_UnitConvert = Convert.ToString(reader["UnitConvert"]);
                    this.m_UnitRate = Convert.ToSingle(reader["UnitRate"]);
                    this.m_Org_Price = Convert.ToSingle(reader["Org_Price"]);
                    this.m_Quantity = Convert.ToSingle(reader["Quantity"]);
                    this.m_AverageCost = Convert.ToSingle(reader["AverageCost"]);
                    this.m_Product_Type_ID = Convert.ToInt32(reader["Product_Type_ID"]);
                    str = "OK";
                }
                reader.Close();
            }
            return str;
        }

        public string GetByStore(string Product_ID)
        {
            string str = "";
            string[] myParams = new string[] { "@Product_ID" };
            object[] myValues = new object[] { Product_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("PRODUCT_GetByStore", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_Product_ID = Convert.ToString(reader["Product_ID"]);
                    this.m_Product_Name = Convert.ToString(reader["Product_Name"]);
                    this.m_Product_Type_ID = Convert.ToInt32(reader["Product_Type_ID"]);
                    this.m_Manufacturer_ID = Convert.ToInt32(reader["Manufacturer_ID"]);
                    this.m_Product_Group_ID = Convert.ToString(reader["Product_Group_ID"]);
                    this.m_Provider_ID = Convert.ToString(reader["Provider_ID"]);
                    this.m_Origin = Convert.ToString(reader["Origin"]);
                    this.m_Barcode = Convert.ToString(reader["Barcode"]);
                    this.m_Unit = Convert.ToString(reader["Unit"]);
                    this.m_UnitConvert = Convert.ToString(reader["UnitConvert"]);
                    this.m_UnitRate = Convert.ToSingle(reader["UnitRate"]);
                    this.m_Org_Price = Convert.ToSingle(reader["Org_Price"]);
                    this.m_Sale_Price = Convert.ToSingle(reader["Sale_Price"]);
                    this.m_Retail_Price = Convert.ToSingle(reader["Retail_Price"]);
                    this.m_Quantity = Convert.ToSingle(reader["Quantity"]);
                    this.m_CurrentCost = Convert.ToSingle(reader["CurrentCost"]);
                    this.m_AverageCost = Convert.ToSingle(reader["AverageCost"]);
                    this.m_Warranty = Convert.ToInt32(reader["Warranty"]);
                    this.m_VAT_ID = Convert.ToSingle(reader["VAT_ID"]);
                    this.m_ImportTax_ID = Convert.ToSingle(reader["ImportTax_ID"]);
                    this.m_ExportTax_ID = Convert.ToSingle(reader["ExportTax_ID"]);
                    this.m_LuxuryTax_ID = Convert.ToSingle(reader["LuxuryTax_ID"]);
                    this.m_Customer_ID = Convert.ToString(reader["Customer_ID"]);
                    this.m_Customer_Name = Convert.ToString(reader["Customer_Name"]);
                    this.m_CostMethod = Convert.ToInt16(reader["CostMethod"]);
                    this.m_MinStock = Convert.ToSingle(reader["MinStock"]);
                    this.m_MaxStock = Convert.ToSingle(reader["MaxStock"]);
                    this.m_Discount = Convert.ToSingle(reader["Discount"]);
                    this.m_Commission = Convert.ToSingle(reader["Commission"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    this.m_Color = Convert.ToString(reader["Color"]);
                    this.m_Expiry = Convert.ToBoolean(reader["Expiry"]);
                    this.m_LimitOrders = Convert.ToSingle(reader["LimitOrders"]);
                    this.m_ExpiryValue = Convert.ToSingle(reader["ExpiryValue"]);
                    this.m_Batch = Convert.ToBoolean(reader["Batch"]);
                    this.m_Depth = Convert.ToSingle(reader["Depth"]);
                    this.m_Height = Convert.ToSingle(reader["Height"]);
                    this.m_Width = Convert.ToSingle(reader["Width"]);
                    this.m_Thickness = Convert.ToSingle(reader["Thickness"]);
                    this.m_Size = Convert.ToString(reader["Size"]);
                    this.m_UserID = Convert.ToString(reader["UserID"]);
                    this.m_Active = Convert.ToBoolean(reader["Active"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public DataTable GetFull()
        {
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("PRODUCT_GetFull");
        }

        public DataTable GetList()
        {
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("PRODUCT_GetList");
        }

        public DataTable GetList_BTP()
        {
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("PRODUCT_Get_BTP");
        }

        public DataTable GetList_Build()
        {
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("PRODUCT_GetList_Build");
        }

        public DataTable GetList_Init(string Product_ID, string Product_Name, string Stock_ID)
        {
            string[] myParams = new string[] { "@Product_ID", "@ProductName", "@Stock_ID" };
            object[] myValues = new object[] { "%" + Product_ID + "%", "%" + Product_Name + "%", Stock_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("INVENTORY_GetList_Init", myParams, myValues);
        }

        public DataTable GetList_TP()
        {
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("PRODUCT_Get_TP");
        }

        public DataTable GetPack()
        {
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("PRODUCT_GetPack");
        }

        public string Insert()
        {
            string[] myParams = new string[] { 
                "@Product_ID", "@Product_Name", "@Product_Type_ID", "@Manufacturer_ID", "@Product_Group_ID", "@Provider_ID", "@Origin", "@Barcode", "@Unit", "@UnitConvert", "@UnitRate", "@Org_Price", "@Sale_Price", "@Retail_Price", "@Quantity", "@CurrentCost", 
                "@AverageCost", "@Warranty", "@VAT_ID", "@ImportTax_ID", "@ExportTax_ID", "@LuxuryTax_ID", "@Customer_ID", "@Customer_Name", "@CostMethod", "@MinStock", "@MaxStock", "@Discount", "@Commission", "@Description", "@Color", "@Expiry", 
                "@LimitOrders", "@ExpiryValue", "@Batch", "@Depth", "@Height", "@Width", "@Thickness", "@Size", "@UserID", "@Active"
             };
            object[] myValues = new object[] { 
                this.m_Product_ID, this.m_Product_Name, this.m_Product_Type_ID, this.m_Manufacturer_ID, this.m_Product_Group_ID, this.m_Provider_ID, this.m_Origin, this.m_Barcode, this.m_Unit, this.m_UnitConvert, this.m_UnitRate, this.m_Org_Price, this.m_Sale_Price, this.m_Retail_Price, this.m_Quantity, this.m_CurrentCost, 
                this.m_AverageCost, this.m_Warranty, this.m_VAT_ID, this.m_ImportTax_ID, this.m_ExportTax_ID, this.m_LuxuryTax_ID, this.m_Customer_ID, this.m_Customer_Name, this.m_CostMethod, this.m_MinStock, this.m_MaxStock, this.m_Discount, this.m_Commission, this.m_Description, this.m_Color, this.m_Expiry, 
                this.m_LimitOrders, this.m_ExpiryValue, this.m_Batch, this.m_Depth, this.m_Height, this.m_Width, this.m_Thickness, this.m_Size, this.m_UserID, this.m_Active
             };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("PRODUCT_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction)
        {
            string[] myParams = new string[] { 
                "@Product_ID", "@Product_Name", "@Product_Type_ID", "@Manufacturer_ID", "@Product_Group_ID", "@Provider_ID", "@Origin", "@Barcode", "@Unit", "@UnitConvert", "@UnitRate", "@Org_Price", "@Sale_Price", "@Retail_Price", "@Quantity", "@CurrentCost", 
                "@AverageCost", "@Warranty", "@VAT_ID", "@ImportTax_ID", "@ExportTax_ID", "@LuxuryTax_ID", "@Customer_ID", "@Customer_Name", "@CostMethod", "@MinStock", "@MaxStock", "@Discount", "@Commission", "@Description", "@Color", "@Expiry", 
                "@LimitOrders", "@ExpiryValue", "@Batch", "@Depth", "@Height", "@Width", "@Thickness", "@Size", "@UserID", "@Active"
             };
            object[] myValues = new object[] { 
                this.m_Product_ID, this.m_Product_Name, this.m_Product_Type_ID, this.m_Manufacturer_ID, this.m_Product_Group_ID, this.m_Provider_ID, this.m_Origin, this.m_Barcode, this.m_Unit, this.m_UnitConvert, this.m_UnitRate, this.m_Org_Price, this.m_Sale_Price, this.m_Retail_Price, this.m_Quantity, this.m_CurrentCost, 
                this.m_AverageCost, this.m_Warranty, this.m_VAT_ID, this.m_ImportTax_ID, this.m_ExportTax_ID, this.m_LuxuryTax_ID, this.m_Customer_ID, this.m_Customer_Name, this.m_CostMethod, this.m_MinStock, this.m_MaxStock, this.m_Discount, this.m_Commission, this.m_Description, this.m_Color, this.m_Expiry, 
                this.m_LimitOrders, this.m_ExpiryValue, this.m_Batch, this.m_Depth, this.m_Height, this.m_Width, this.m_Thickness, this.m_Size, this.m_UserID, this.m_Active
             };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "PRODUCT_Insert", myParams, myValues);
        }

        public string Insert(string Product_ID, string Product_Name, int Product_Type_ID, int Manufacturer_ID, string Product_Group_ID, string Provider_ID, string Origin, string Barcode, string Unit, string UnitConvert, double UnitRate, double Org_Price, double Sale_Price, double Retail_Price, double Quantity, double CurrentCost, double AverageCost, int Warranty, double VAT_ID, double ImportTax_ID, double ExportTax_ID, double LuxuryTax_ID, string Customer_ID, string Customer_Name, int CostMethod, double MinStock, double MaxStock, double Discount, double Commission, string Description, string Color, bool Expiry, double LimitOrders, double ExpiryValue, bool Batch, double Depth, double Height, double Width, double Thickness, string Size, string UserID, bool Active)
        {
            string[] myParams = new string[] { 
                "@Product_ID", "@Product_Name", "@Product_Type_ID", "@Manufacturer_ID", "@Product_Group_ID", "@Provider_ID", "@Origin", "@Barcode", "@Unit", "@UnitConvert", "@UnitRate", "@Org_Price", "@Sale_Price", "@Retail_Price", "@Quantity", "@CurrentCost", 
                "@AverageCost", "@Warranty", "@VAT_ID", "@ImportTax_ID", "@ExportTax_ID", "@LuxuryTax_ID", "@Customer_ID", "@Customer_Name", "@CostMethod", "@MinStock", "@MaxStock", "@Discount", "@Commission", "@Description", "@Color", "@Expiry", 
                "@LimitOrders", "@ExpiryValue", "@Batch", "@Depth", "@Height", "@Width", "@Thickness", "@Size", "@UserID", "@Active"
             };
            object[] myValues = new object[] { 
                Product_ID, Product_Name, Product_Type_ID, Manufacturer_ID, Product_Group_ID, Provider_ID, Origin, Barcode, Unit, UnitConvert, UnitRate, Org_Price, Sale_Price, Retail_Price, Quantity, CurrentCost, 
                AverageCost, Warranty, VAT_ID, ImportTax_ID, ExportTax_ID, LuxuryTax_ID, Customer_ID, Customer_Name, CostMethod, MinStock, MaxStock, Discount, Commission, Description, Color, Expiry, 
                LimitOrders, ExpiryValue, Batch, Depth, Height, Width, Thickness, Size, UserID, Active
             };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("PRODUCT_Insert", myParams, myValues);
        }

        public string Insert(SqlConnection myConnection, string Product_ID, string Product_Name, int Product_Type_ID, int Manufacturer_ID, string Product_Group_ID, string Provider_ID, string Origin, string Barcode, string Unit, string UnitConvert, double UnitRate, double Org_Price, double Sale_Price, double Retail_Price, double Quantity, double CurrentCost, double AverageCost, int Warranty, double VAT_ID, double ImportTax_ID, double ExportTax_ID, double LuxuryTax_ID, string Customer_ID, string Customer_Name, int CostMethod, double MinStock, double MaxStock, double Discount, double Commission, string Description, string Color, bool Expiry, double LimitOrders, double ExpiryValue, bool Batch, double Depth, double Height, double Width, double Thickness, string Size, string UserID, bool Active)
        {
            string[] myParams = new string[] { 
                "@Product_ID", "@Product_Name", "@Product_Type_ID", "@Manufacturer_ID", "@Product_Group_ID", "@Provider_ID", "@Origin", "@Barcode", "@Unit", "@UnitConvert", "@UnitRate", "@Org_Price", "@Sale_Price", "@Retail_Price", "@Quantity", "@CurrentCost", 
                "@AverageCost", "@Warranty", "@VAT_ID", "@ImportTax_ID", "@ExportTax_ID", "@LuxuryTax_ID", "@Customer_ID", "@Customer_Name", "@CostMethod", "@MinStock", "@MaxStock", "@Discount", "@Commission", "@Description", "@Color", "@Expiry", 
                "@LimitOrders", "@ExpiryValue", "@Batch", "@Depth", "@Height", "@Width", "@Thickness", "@Size", "@UserID", "@Active"
             };
            object[] myValues = new object[] { 
                Product_ID, Product_Name, Product_Type_ID, Manufacturer_ID, Product_Group_ID, Provider_ID, Origin, Barcode, Unit, UnitConvert, UnitRate, Org_Price, Sale_Price, Retail_Price, Quantity, CurrentCost, 
                AverageCost, Warranty, VAT_ID, ImportTax_ID, ExportTax_ID, LuxuryTax_ID, Customer_ID, Customer_Name, CostMethod, MinStock, MaxStock, Discount, Commission, Description, Color, Expiry, 
                LimitOrders, ExpiryValue, Batch, Depth, Height, Width, Thickness, Size, UserID, Active
             };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "PRODUCT_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction, string Product_ID, string Product_Name, int Product_Type_ID, int Manufacturer_ID, string Product_Group_ID, string Provider_ID, string Origin, string Barcode, string Unit, string UnitConvert, double UnitRate, double Org_Price, double Sale_Price, double Retail_Price, double Quantity, double CurrentCost, double AverageCost, int Warranty, double VAT_ID, double ImportTax_ID, double ExportTax_ID, double LuxuryTax_ID, string Customer_ID, string Customer_Name, int CostMethod, double MinStock, double MaxStock, double Discount, double Commission, string Description, string Color, bool Expiry, double LimitOrders, double ExpiryValue, bool Batch, double Depth, double Height, double Width, double Thickness, string Size, string UserID, bool Active)
        {
            string[] myParams = new string[] { 
                "@Product_ID", "@Product_Name", "@Product_Type_ID", "@Manufacturer_ID", "@Product_Group_ID", "@Provider_ID", "@Origin", "@Barcode", "@Unit", "@UnitConvert", "@UnitRate", "@Org_Price", "@Sale_Price", "@Retail_Price", "@Quantity", "@CurrentCost", 
                "@AverageCost", "@Warranty", "@VAT_ID", "@ImportTax_ID", "@ExportTax_ID", "@LuxuryTax_ID", "@Customer_ID", "@Customer_Name", "@CostMethod", "@MinStock", "@MaxStock", "@Discount", "@Commission", "@Description", "@Color", "@Expiry", 
                "@LimitOrders", "@ExpiryValue", "@Batch", "@Depth", "@Height", "@Width", "@Thickness", "@Size", "@UserID", "@Active"
             };
            object[] myValues = new object[] { 
                Product_ID, Product_Name, Product_Type_ID, Manufacturer_ID, Product_Group_ID, Provider_ID, Origin, Barcode, Unit, UnitConvert, UnitRate, Org_Price, Sale_Price, Retail_Price, Quantity, CurrentCost, 
                AverageCost, Warranty, VAT_ID, ImportTax_ID, ExportTax_ID, LuxuryTax_ID, Customer_ID, Customer_Name, CostMethod, MinStock, MaxStock, Discount, Commission, Description, Color, Expiry, 
                LimitOrders, ExpiryValue, Batch, Depth, Height, Width, Thickness, Size, UserID, Active
             };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "PRODUCT_Insert", myParams, myValues);
        }

        public string NewID()
        {
            return SqlHelper.GenCode("PRODUCT", "Product_ID", "HH");
        }

        public DataTable Search(string Product_ID, string Product_Name)
        {
            string[] myParams = new string[] { "@Product_ID", "@Product_Name" };
            object[] myValues = new object[] { "%" + Product_ID + "%", "%" + Product_Name + "%" };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("PRODUCT_Search", myParams, myValues);
        }

        public string Update()
        {
            string[] myParams = new string[] { 
                "@Product_ID", "@Product_Name", "@Product_Type_ID", "@Manufacturer_ID", "@Product_Group_ID", "@Provider_ID", "@Origin", "@Barcode", "@Unit", "@UnitConvert", "@UnitRate", "@Org_Price", "@Sale_Price", "@Retail_Price", "@Quantity", "@CurrentCost", 
                "@AverageCost", "@Warranty", "@VAT_ID", "@ImportTax_ID", "@ExportTax_ID", "@LuxuryTax_ID", "@Customer_ID", "@Customer_Name", "@CostMethod", "@MinStock", "@MaxStock", "@Discount", "@Commission", "@Description", "@Color", "@Expiry", 
                "@LimitOrders", "@ExpiryValue", "@Batch", "@Depth", "@Height", "@Width", "@Thickness", "@Size", "@UserID", "@Active"
             };
            object[] myValues = new object[] { 
                this.m_Product_ID, this.m_Product_Name, this.m_Product_Type_ID, this.m_Manufacturer_ID, this.m_Product_Group_ID, this.m_Provider_ID, this.m_Origin, this.m_Barcode, this.m_Unit, this.m_UnitConvert, this.m_UnitRate, this.m_Org_Price, this.m_Sale_Price, this.m_Retail_Price, this.m_Quantity, this.m_CurrentCost, 
                this.m_AverageCost, this.m_Warranty, this.m_VAT_ID, this.m_ImportTax_ID, this.m_ExportTax_ID, this.m_LuxuryTax_ID, this.m_Customer_ID, this.m_Customer_Name, this.m_CostMethod, this.m_MinStock, this.m_MaxStock, this.m_Discount, this.m_Commission, this.m_Description, this.m_Color, this.m_Expiry, 
                this.m_LimitOrders, this.m_ExpiryValue, this.m_Batch, this.m_Depth, this.m_Height, this.m_Width, this.m_Thickness, this.m_Size, this.m_UserID, this.m_Active
             };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("PRODUCT_Update", myParams, myValues);
        }

        public string Update(SqlTransaction myTransaction)
        {
            string[] myParams = new string[] { 
                "@Product_ID", "@Product_Name", "@Product_Type_ID", "@Manufacturer_ID", "@Product_Group_ID", "@Provider_ID", "@Origin", "@Barcode", "@Unit", "@UnitConvert", "@UnitRate", "@Org_Price", "@Sale_Price", "@Retail_Price", "@Quantity", "@CurrentCost", 
                "@AverageCost", "@Warranty", "@VAT_ID", "@ImportTax_ID", "@ExportTax_ID", "@LuxuryTax_ID", "@Customer_ID", "@Customer_Name", "@CostMethod", "@MinStock", "@MaxStock", "@Discount", "@Commission", "@Description", "@Color", "@Expiry", 
                "@LimitOrders", "@ExpiryValue", "@Batch", "@Depth", "@Height", "@Width", "@Thickness", "@Size", "@UserID", "@Active"
             };
            object[] myValues = new object[] { 
                this.m_Product_ID, this.m_Product_Name, this.m_Product_Type_ID, this.m_Manufacturer_ID, this.m_Product_Group_ID, this.m_Provider_ID, this.m_Origin, this.m_Barcode, this.m_Unit, this.m_UnitConvert, this.m_UnitRate, this.m_Org_Price, this.m_Sale_Price, this.m_Retail_Price, this.m_Quantity, this.m_CurrentCost, 
                this.m_AverageCost, this.m_Warranty, this.m_VAT_ID, this.m_ImportTax_ID, this.m_ExportTax_ID, this.m_LuxuryTax_ID, this.m_Customer_ID, this.m_Customer_Name, this.m_CostMethod, this.m_MinStock, this.m_MaxStock, this.m_Discount, this.m_Commission, this.m_Description, this.m_Color, this.m_Expiry, 
                this.m_LimitOrders, this.m_ExpiryValue, this.m_Batch, this.m_Depth, this.m_Height, this.m_Width, this.m_Thickness, this.m_Size, this.m_UserID, this.m_Active
             };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "PRODUCT_Update", myParams, myValues);
        }

        public string Update(SqlConnection myConnection, string Product_ID, string Product_Group_ID)
        {
            SqlHelper helper = new SqlHelper();
            helper.CommandType = CommandType.Text;
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return helper.ExecuteNonQuery(myConnection, "UPDATE PRODUCT SET Product_Group_ID = N'" + Product_Group_ID + "' WHERE Product_ID=N'" + Product_ID + "'");
        }

        public string Update(SqlTransaction myTransaction, string Product_ID, Image photo)
        {
            byte[] buffer;
            SqlHelper helper = new SqlHelper();
            helper.CommandType = CommandType.Text;
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            if (photo != null)
            {
                MemoryStream stream = new MemoryStream();
                photo.Save(stream, photo.RawFormat);
                buffer = stream.GetBuffer();
                stream.Close();
            }
            else
            {
                buffer = new byte[2];
            }
            string[] myParams = new string[] { "@Product_ID", "@Photo" };
            object[] myValues = new object[] { Product_ID, buffer };
            return helper.ExecuteNonQuery(myTransaction, "Update PRODUCT set Photo=@Photo WHERE Product_ID=@Product_ID", myParams, myValues);
        }

        public string Update(SqlTransaction myTransaction, string idSrc, string idDesc)
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            string[] myParams = new string[] { "@IdSrc", "@IdDesc" };
            object[] myValues = new object[] { idSrc, idDesc };
            return helper.ExecuteNonQuery(myTransaction, "PRODUCT_mergByProductId", myParams, myValues);
        }

        public string Update(string Product_ID, string Product_Name, int Product_Type_ID, int Manufacturer_ID, string Product_Group_ID, string Provider_ID, string Origin, string Barcode, string Unit, string UnitConvert, double UnitRate, double Org_Price, double Sale_Price, double Retail_Price, double Quantity, double CurrentCost, double AverageCost, int Warranty, double VAT_ID, double ImportTax_ID, double ExportTax_ID, double LuxuryTax_ID, string Customer_ID, string Customer_Name, int CostMethod, double MinStock, double MaxStock, double Discount, double Commission, string Description, string Color, bool Expiry, double LimitOrders, double ExpiryValue, bool Batch, double Depth, double Height, double Width, double Thickness, string Size, string UserID, bool Active)
        {
            string[] myParams = new string[] { 
                "@Product_ID", "@Product_Name", "@Product_Type_ID", "@Manufacturer_ID", "@Product_Group_ID", "@Provider_ID", "@Origin", "@Barcode", "@Unit", "@UnitConvert", "@UnitRate", "@Org_Price", "@Sale_Price", "@Retail_Price", "@Quantity", "@CurrentCost", 
                "@AverageCost", "@Warranty", "@VAT_ID", "@ImportTax_ID", "@ExportTax_ID", "@LuxuryTax_ID", "@Customer_ID", "@Customer_Name", "@CostMethod", "@MinStock", "@MaxStock", "@Discount", "@Commission", "@Description", "@Color", "@Expiry", 
                "@LimitOrders", "@ExpiryValue", "@Batch", "@Depth", "@Height", "@Width", "@Thickness", "@Size", "@UserID", "@Active"
             };
            object[] myValues = new object[] { 
                Product_ID, Product_Name, Product_Type_ID, Manufacturer_ID, Product_Group_ID, Provider_ID, Origin, Barcode, Unit, UnitConvert, UnitRate, Org_Price, Sale_Price, Retail_Price, Quantity, CurrentCost, 
                AverageCost, Warranty, VAT_ID, ImportTax_ID, ExportTax_ID, LuxuryTax_ID, Customer_ID, Customer_Name, CostMethod, MinStock, MaxStock, Discount, Commission, Description, Color, Expiry, 
                LimitOrders, ExpiryValue, Batch, Depth, Height, Width, Thickness, Size, UserID, Active
             };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("PRODUCT_Update", myParams, myValues);
        }

        public string Update(SqlConnection myConnection, string Product_ID, string Product_Name, int Product_Type_ID, int Manufacturer_ID, string Product_Group_ID, string Provider_ID, string Origin, string Barcode, string Unit, string UnitConvert, double UnitRate, double Org_Price, double Sale_Price, double Retail_Price, double Quantity, double CurrentCost, double AverageCost, int Warranty, double VAT_ID, double ImportTax_ID, double ExportTax_ID, double LuxuryTax_ID, string Customer_ID, string Customer_Name, int CostMethod, double MinStock, double MaxStock, double Discount, double Commission, string Description, string Color, bool Expiry, double LimitOrders, double ExpiryValue, bool Batch, double Depth, double Height, double Width, double Thickness, string Size, string UserID, bool Active)
        {
            string[] myParams = new string[] { 
                "@Product_ID", "@Product_Name", "@Product_Type_ID", "@Manufacturer_ID", "@Product_Group_ID", "@Provider_ID", "@Origin", "@Barcode", "@Unit", "@UnitConvert", "@UnitRate", "@Org_Price", "@Sale_Price", "@Retail_Price", "@Quantity", "@CurrentCost", 
                "@AverageCost", "@Warranty", "@VAT_ID", "@ImportTax_ID", "@ExportTax_ID", "@LuxuryTax_ID", "@Customer_ID", "@Customer_Name", "@CostMethod", "@MinStock", "@MaxStock", "@Discount", "@Commission", "@Description", "@Color", "@Expiry", 
                "@LimitOrders", "@ExpiryValue", "@Batch", "@Depth", "@Height", "@Width", "@Thickness", "@Size", "@UserID", "@Active"
             };
            object[] myValues = new object[] { 
                Product_ID, Product_Name, Product_Type_ID, Manufacturer_ID, Product_Group_ID, Provider_ID, Origin, Barcode, Unit, UnitConvert, UnitRate, Org_Price, Sale_Price, Retail_Price, Quantity, CurrentCost, 
                AverageCost, Warranty, VAT_ID, ImportTax_ID, ExportTax_ID, LuxuryTax_ID, Customer_ID, Customer_Name, CostMethod, MinStock, MaxStock, Discount, Commission, Description, Color, Expiry, 
                LimitOrders, ExpiryValue, Batch, Depth, Height, Width, Thickness, Size, UserID, Active
             };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "PRODUCT_Update", myParams, myValues);
        }

        public string Update(SqlTransaction myTransaction, string Product_ID, string Product_Name, int Product_Type_ID, int Manufacturer_ID, string Product_Group_ID, string Provider_ID, string Origin, string Barcode, string Unit, string UnitConvert, double UnitRate, double Org_Price, double Sale_Price, double Retail_Price, double Quantity, double CurrentCost, double AverageCost, int Warranty, double VAT_ID, double ImportTax_ID, double ExportTax_ID, double LuxuryTax_ID, string Customer_ID, string Customer_Name, int CostMethod, double MinStock, double MaxStock, double Discount, double Commission, string Description, string Color, bool Expiry, double LimitOrders, double ExpiryValue, bool Batch, double Depth, double Height, double Width, double Thickness, string Size, string UserID, bool Active)
        {
            string[] myParams = new string[] { 
                "@Product_ID", "@Product_Name", "@Product_Type_ID", "@Manufacturer_ID", "@Product_Group_ID", "@Provider_ID", "@Origin", "@Barcode", "@Unit", "@UnitConvert", "@UnitRate", "@Org_Price", "@Sale_Price", "@Retail_Price", "@Quantity", "@CurrentCost", 
                "@AverageCost", "@Warranty", "@VAT_ID", "@ImportTax_ID", "@ExportTax_ID", "@LuxuryTax_ID", "@Customer_ID", "@Customer_Name", "@CostMethod", "@MinStock", "@MaxStock", "@Discount", "@Commission", "@Description", "@Color", "@Expiry", 
                "@LimitOrders", "@ExpiryValue", "@Batch", "@Depth", "@Height", "@Width", "@Thickness", "@Size", "@UserID", "@Active"
             };
            object[] myValues = new object[] { 
                Product_ID, Product_Name, Product_Type_ID, Manufacturer_ID, Product_Group_ID, Provider_ID, Origin, Barcode, Unit, UnitConvert, UnitRate, Org_Price, Sale_Price, Retail_Price, Quantity, CurrentCost, 
                AverageCost, Warranty, VAT_ID, ImportTax_ID, ExportTax_ID, LuxuryTax_ID, Customer_ID, Customer_Name, CostMethod, MinStock, MaxStock, Discount, Commission, Description, Color, Expiry, 
                LimitOrders, ExpiryValue, Batch, Depth, Height, Width, Thickness, Size, UserID, Active
             };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "PRODUCT_Update", myParams, myValues);
        }

        public bool Active
        {
            get
            {
                return this.m_Active;
            }
            set
            {
                this.m_Active = value;
            }
        }

        public double AverageCost
        {
            get
            {
                return this.m_AverageCost;
            }
            set
            {
                this.m_AverageCost = value;
            }
        }

        public string Barcode
        {
            get
            {
                return this.m_Barcode;
            }
            set
            {
                this.m_Barcode = value;
            }
        }

        public bool Batch
        {
            get
            {
                return this.m_Batch;
            }
            set
            {
                this.m_Batch = value;
            }
        }

        public string Color
        {
            get
            {
                return this.m_Color;
            }
            set
            {
                this.m_Color = value;
            }
        }

        public double Commission
        {
            get
            {
                return this.m_Commission;
            }
            set
            {
                this.m_Commission = value;
            }
        }

        public int CostMethod
        {
            get
            {
                return this.m_CostMethod;
            }
            set
            {
                this.m_CostMethod = value;
            }
        }

        public double CurrentCost
        {
            get
            {
                return this.m_CurrentCost;
            }
            set
            {
                this.m_CurrentCost = value;
            }
        }

        public string Customer_ID
        {
            get
            {
                return this.m_Customer_ID;
            }
            set
            {
                this.m_Customer_ID = value;
            }
        }

        public string Customer_Name
        {
            get
            {
                return this.m_Customer_Name;
            }
            set
            {
                this.m_Customer_Name = value;
            }
        }

        public double Depth
        {
            get
            {
                return this.m_Depth;
            }
            set
            {
                this.m_Depth = value;
            }
        }

        public string Description
        {
            get
            {
                return this.m_Description;
            }
            set
            {
                this.m_Description = value;
            }
        }

        public double Discount
        {
            get
            {
                return this.m_Discount;
            }
            set
            {
                this.m_Discount = value;
            }
        }

        public bool Expiry
        {
            get
            {
                return this.m_Expiry;
            }
            set
            {
                this.m_Expiry = value;
            }
        }

        public double ExpiryValue
        {
            get
            {
                return this.m_ExpiryValue;
            }
            set
            {
                this.m_ExpiryValue = value;
            }
        }

        public double ExportTax_ID
        {
            get
            {
                return this.m_ExportTax_ID;
            }
            set
            {
                this.m_ExportTax_ID = value;
            }
        }

        public double Height
        {
            get
            {
                return this.m_Height;
            }
            set
            {
                this.m_Height = value;
            }
        }

        public double ImportTax_ID
        {
            get
            {
                return this.m_ImportTax_ID;
            }
            set
            {
                this.m_ImportTax_ID = value;
            }
        }

        public double LimitOrders
        {
            get
            {
                return this.m_LimitOrders;
            }
            set
            {
                this.m_LimitOrders = value;
            }
        }

        public double LuxuryTax_ID
        {
            get
            {
                return this.m_LuxuryTax_ID;
            }
            set
            {
                this.m_LuxuryTax_ID = value;
            }
        }

        public int Manufacturer_ID
        {
            get
            {
                return this.m_Manufacturer_ID;
            }
            set
            {
                this.m_Manufacturer_ID = value;
            }
        }

        public double MaxStock
        {
            get
            {
                return this.m_MaxStock;
            }
            set
            {
                this.m_MaxStock = value;
            }
        }

        public double MinStock
        {
            get
            {
                return this.m_MinStock;
            }
            set
            {
                this.m_MinStock = value;
            }
        }

        public double Org_Price
        {
            get
            {
                return this.m_Org_Price;
            }
            set
            {
                this.m_Org_Price = value;
            }
        }

        public string Origin
        {
            get
            {
                return this.m_Origin;
            }
            set
            {
                this.m_Origin = value;
            }
        }

        public Image Photo
        {
            get
            {
                return this.m_photo;
            }
            set
            {
                this.m_photo = value;
            }
        }

        public string Product_Group_ID
        {
            get
            {
                return this.m_Product_Group_ID;
            }
            set
            {
                this.m_Product_Group_ID = value;
            }
        }

        public string Product_ID
        {
            get
            {
                return this.m_Product_ID;
            }
            set
            {
                this.m_Product_ID = value;
            }
        }

        public string Product_Name
        {
            get
            {
                return this.m_Product_Name;
            }
            set
            {
                this.m_Product_Name = value;
            }
        }

        public int Product_Type_ID
        {
            get
            {
                return this.m_Product_Type_ID;
            }
            set
            {
                this.m_Product_Type_ID = value;
            }
        }

        public string ProductName
        {
            get
            {
                return "Class PRODUCT";
            }
        }

        public string ProductVersion
        {
            get
            {
                return "1.0.0.0";
            }
        }

        public string Provider_ID
        {
            get
            {
                return this.m_Provider_ID;
            }
            set
            {
                this.m_Provider_ID = value;
            }
        }

        public double Quantity
        {
            get
            {
                return this.m_Quantity;
            }
            set
            {
                this.m_Quantity = value;
            }
        }

        public double Retail_Price
        {
            get
            {
                return this.m_Retail_Price;
            }
            set
            {
                this.m_Retail_Price = value;
            }
        }

        public double Sale_Price
        {
            get
            {
                return this.m_Sale_Price;
            }
            set
            {
                this.m_Sale_Price = value;
            }
        }

        public string Size
        {
            get
            {
                return this.m_Size;
            }
            set
            {
                this.m_Size = value;
            }
        }

        public double Thickness
        {
            get
            {
                return this.m_Thickness;
            }
            set
            {
                this.m_Thickness = value;
            }
        }

        public string Unit
        {
            get
            {
                return this.m_Unit;
            }
            set
            {
                this.m_Unit = value;
            }
        }

        public string UnitConvert
        {
            get
            {
                return this.m_UnitConvert;
            }
            set
            {
                this.m_UnitConvert = value;
            }
        }

        public double UnitRate
        {
            get
            {
                return this.m_UnitRate;
            }
            set
            {
                this.m_UnitRate = value;
            }
        }

        public string UserID
        {
            get
            {
                return this.m_UserID;
            }
            set
            {
                this.m_UserID = value;
            }
        }

        public double VAT_ID
        {
            get
            {
                return this.m_VAT_ID;
            }
            set
            {
                this.m_VAT_ID = value;
            }
        }

        public int Warranty
        {
            get
            {
                return this.m_Warranty;
            }
            set
            {
                this.m_Warranty = value;
            }
        }

        public double Width
        {
            get
            {
                return this.m_Width;
            }
            set
            {
                this.m_Width = value;
            }
        }
    }
}

